from rx import Observable, Observer
from tqdm import *
import time
from memory_profiler import *

# t1 = time.clock()
# fs = open("2017-09-21.csv", "r")
# fs.readlines()
# t2 = time.clock()
# print(t2-t1)

s = ""
t1 = time.clock()
for i in open("2017-09-21.csv", "r"):
    s = i
    print(i)
# with open("2017-09-21.csv", "r") as file:
#     fi = file.readlines()
#     for line in fi:
#         s = line
t2 = time.clock()
print(t2-t1)


# 逐笔交易数据
def ticks(observer):
    with open("2017-09-21.csv", "r") as file:
        fi = file.readlines()
        for line in tqdm(fi):
            observer.on_next(line)
        observer.on_completed()


class PrintObserver(Observer):

    def on_next(self, value):
        print("Received {0}".format(value))

    def on_completed(self):
        print("Done!")

    def on_error(self, error):
        print("Error Occurred: {0}".format(error))

source = Observable.create(ticks)


source.map(lambda x: x.split(','))\
    # .subscribe(lambda x: x)